package com.gotloop.jdo;

import java.io.Serializable;
import java.util.Date;

import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.gotloop.jdo.key.VotePK;

/**
 * A vote groups a User and a Loop.
 * @author jibhaine
 *
 */
@PersistenceCapable(objectIdClass = VotePK.class)
public class Vote implements Serializable {

	/**
	 * Generated serial version UID.
	 */
	private static final long serialVersionUID = -3540354685777096705L;

	/**
	 * The user who voted.
	 */
	@Persistent
	@PrimaryKey
	private UserProfile userProfile;

	/**
	 * The loop he voted for (or against).
	 */
	@Persistent
	@PrimaryKey
	private Loop loop;
	
	/**
	 * Amount of points positive or negative.
	 */
	@Persistent
	private int points;

	/**
	 * Date of vote.
	 */
	@Persistent
	private Date voteDate;

	/**
	 * Public Constructor.
	 * @param pUser		the User who voted.
	 * @param pLoop		the Loop he voted for.
	 * @param pPoints	the number of Points(positive or negative)
	 */
	public Vote(UserProfile pUser, Loop pLoop, int pPoints) {
		this.userProfile = pUser;
		this.loop = pLoop;
		this.points = pPoints;
		this.voteDate = new Date();
	}

	/**
	 * Get accessor for user.
	 * @return the user to get
	 */
	public UserProfile getUserProfile() {
		return userProfile;
	}

	/**
	 * Set accessor for user.
	 * @param pUser the user to set
	 */
	public void setUserProfile(UserProfile pUser) {
		this.userProfile = pUser;
	}

	/**
	 * Get accessor for loop.
	 * @return the loop to get
	 */
	public Loop getLoop() {
		return loop;
	}

	/**
	 * Set accessor for loop.
	 * @param pLoop the loop to set
	 */
	public void setLoop(Loop pLoop) {
		this.loop = pLoop;
	}

	/**
	 * Get accessor for points.
	 * @return the points to get
	 */
	public int getPoints() {
		return points;
	}

	/**
	 * Set accessor for points.
	 * @param pPoints the points to set
	 */
	public void setPoints(int pPoints) {
		this.points = pPoints;
	}

	/**
	 * Get accessor for voteDate.
	 * @return the voteDate to get
	 */
	public Date getVoteDate() {
		return voteDate;
	}

	/**
	 * Set accessor for voteDate.
	 * @param pVoteDate the voteDate to set
	 */
	public void setVoteDate(Date pVoteDate) {
		this.voteDate = pVoteDate;
	}
	
}
